package com.xlh.enums.user;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;

/**
 * 角色枚举类
 *
 * @author cheer
 */
@Getter
@AllArgsConstructor
public enum RoleEnum {

    TEACHER(1, "普通教师"),
    STUDENT(2, "学生"),
    ADMIN(3, "管理员"),
    SUPER_ADMIN(4, "超级管理员"),

    UNIVERSITY_TEACHER(5, "高校教师"),
    MARKET_TEACHER(6, "销售教师"),
    INTERNET_ADMIN(7, "互联网管理员");

    private Integer roleCode;

    private String roleName;

    public static String codeToName(Integer code) {
        for (RoleEnum roleEnum : RoleEnum.values()) {
            if (Objects.equals(roleEnum.getRoleCode(), code)) {
                return roleEnum.name().toUpperCase();
            }
        }
        return null;
    }

    public static RoleEnum getByCode(Integer code) {
        for (RoleEnum roleEnum : RoleEnum.values()) {
            if (Objects.equals(roleEnum.getRoleCode(), code)) {
                return roleEnum;
            }
        }
        return null;
    }

    public static Integer getCodeByName(String name){
        for (RoleEnum roleEnum : RoleEnum.values()) {
            if (Objects.equals(roleEnum.getRoleName(), name)) {
                return roleEnum.getRoleCode();
            }
        }
        return null;
    }

    public static RoleEnum getByName(String name){
        if (name == null) return null;
        for (RoleEnum roleEnum : RoleEnum.values()) {
            if (Objects.equals(roleEnum.getRoleName(), name)) {
                return roleEnum;
            }
        }
        return null;
    }

}
